@functions{   
	private DateTime? Value
	{
		get
		{
			DateTime? value = null;
			if (ViewData.Model != null)
			{
				value = Convert.ToDateTime(ViewData.Model, System.Globalization.CultureInfo.CurrentCulture);
			}
			return value;
		}
	}

	private bool PickTime
	{
		get
		{
			if (ViewData.ContainsKey("pickTime"))
			{
				return ViewData["pickTime"].Convert<bool>();
			}
			else if (ViewData.ContainsKey("pickTimeFieldIds"))
			{
				var ids = ViewData["pickTimeFieldIds"] as List<string>;
				var id = ViewData.TemplateInfo.GetFullHtmlFieldId(string.Empty);
				return ids.Contains(id);
			}
			return false;
		}
	}

	private string CssClass
	{
		get
		{
			var cls = "input-group date datetimepicker-group";

			if (ViewData.ContainsKey("size"))
			{
				cls += " input-group-" + ViewData["size"].Convert<string>();
			}

			return cls;
		}
	}
}

@{
    var id = ViewData.TemplateInfo.GetFullHtmlFieldId(string.Empty);
	var format = PickTime ? "L LT" : "L";
    var value = String.Empty;
    if (Value.HasValue && Value.Value > DateTime.MinValue)
	{
		value = PickTime ? Value.Value.ToString() : Value.Value.ToShortDateString();
    }
}

<div class="@CssClass" id="@id-parent" data-date="@value" data-target-input="nearest">
    @Html.TextBox("", value, new { @class = "form-control datetimepicker-input", data_target = "#" + id + "-parent", data_format = format })
	<div class="input-group-append input-group-addon" data-target="#@(id)-parent" data-toggle="datetimepicker">
		<span class="input-group-text"><i class="far fa-calendar-alt"></i></span>
	</div>
</div>

<script data-origin="DateTime">
	$(function () {
		$("#@(id)-parent").datetimepicker({ format: '@(format)', useCurrent: false, locale: moment.locale() });
	});
</script>